package com.zkingsoft.services.impl;

import com.zkingsoft.services.BonusDetailService;
import com.zkingsoft.services.BonusinfoService;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.model.BonusDetail;
import com.zkingsoft.model.Bonusinfo;
import com.zkingsoft.dao.BonusDetailDao;
import com.zkingsoft.dao.BonusinfoDao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import javax.annotation.Resource;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-11-17 11:32
 */
@Service("bonusinfoService")
public class  BonusinfoServiceImpl implements    BonusinfoService  {

	
	
	@Autowired
	private BonusinfoDao bonusinfoDao;
	
	@Autowired
	private BonusDetailDao bonusDetailDao;
	
	@Override
	public int add(Bonusinfo bonusinfo){
		int count = 0;
		bonusinfoDao.insert(bonusinfo);
		for(BonusDetail bonusDetail : bonusinfo.getBdList()){
			bonusDetail.setBiId(bonusinfo.getBiId());
			bonusDetailDao.insert(bonusDetail);
			count++;
		}
		return count;
	}
	

	@Override
	public int adds(List<Bonusinfo> bonusinfoList) {
		int count=0;
		/*for (Bonusinfo bonusinfo : bonusinfoList){
			bonusinfo.setsId(bonusinfo.getsId());
			bonusinfo.setsClass(bonusinfo.getsClass());
			bonusinfo.setbName(bonusinfo.getbName());
			bonusinfo.setBiMoney(bonusinfo.getBiMoney());
			bonusinfo.setbPayee(bonusinfo.getbPayee());
			bonusinfo.setbPosition(bonusinfo.getbPosition());
			bonusinfo.setBiDate(bonusinfo.getBiDate());
			bonusinfo.setBiRemark(bonusinfo.getBiRemark());
			bonusinfoDao.insert(bonusinfo);
			 count++;
		}*/
		return count;
	}
	
	
   	
    @Override
    @Transactional
	public int modify(Bonusinfo bonusinfo){
    	int count = 0;
    	bonusinfoDao.update(bonusinfo);
    	bonusDetailDao.deleteBybId(bonusinfo.getBiId());
    	for(BonusDetail bonusDetail : bonusinfo.getBdList()){
    		if(bonusDetail.getBdPayee()==null){
    			continue;
    		}
    			bonusDetail.setBiId(bonusinfo.getBiId());
    			bonusDetailDao.insert(bonusDetail);
    		count++;
    	}
		return count;
	}
	
	
	@Override
	public int removeByModel(Bonusinfo bonusinfo){
	
		return bonusinfoDao.deleteByModel(bonusinfo);
	
	}
	
	
	@Override
	public List<Bonusinfo> findInPage(Bonusinfo bonusinfo,  PaginationVO pageVo){
	
		return bonusinfoDao.selectInPage(bonusinfo , pageVo);
	
	}
	
	@Override
	public List<Bonusinfo> findByModel(Bonusinfo bonusinfo){
	
		return bonusinfoDao.selectByModel(bonusinfo);
	
	}
	
	@Override
	public int  findTotal(Bonusinfo bonusinfo){
	
		return bonusinfoDao.selectTotalRecord(bonusinfo);
	
	}
	
	@Override
	public Bonusinfo findById(Long biId){
	
		return bonusinfoDao.selectById(biId);
	
	}

	@Override
	public int remove(List<Long> list) {
		return bonusinfoDao.deleteByIds(list);
	}

	@Override
	public int removeById(Long biId) {
		return bonusinfoDao.deleteById(biId);
	}

}